<template>
  <div class="form-single-fragment" style="position: relative;">
    <el-form ref="formEditFlowRecruitDetail" :model="formData" class="full-width-input" :rules="rules" style="width: 100%;"
      label-width="120px" size="mini" label-position="right" @submit.native.prevent>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="招聘岗位" prop="RecruitDetail.post">
            <el-select class="input-item" v-model="formData.RecruitDetail.post"
            :clearable="true"
            filterable
            placeholder="招聘岗位"
             @change="onRoomNameValueChange"
              >
              <el-option v-for="item in postTypeList" :key="item.id" :value="item.id" :label="item.name" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="希望到岗日期" prop="RecruitDetail.arrivalDate">
            <el-date-picker class="input-item" v-model="formData.RecruitDetail.arrivalDate" :clearable="true"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              type="date" align="left"
              placeholder="希望到岗日期"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="招聘人数" prop="RecruitDetail.recruitNumber">
            <el-input-number class="input-item" v-model="formData.RecruitDetail.recruitNumber"
              :clearable="true"
              :min="1"
              :max="1"
              :step="1"
              placeholder="招聘人数"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="招聘薪资" prop="RecruitDetail.wages">
            <el-input-number class="input-item" v-model="formData.RecruitDetail.wages"
              :clearable="true"
              :min="1"
              :max="999999999"
              :step="100"
              :precision="2"
              placeholder="招聘薪资"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="招聘说明" prop="RecruitDetail.remark">
            <el-input class="input-item" v-model="formData.RecruitDetail.remark"
              type="textarea"
              :autosize="{minRows: 2, maxRows: 4}"
              :clearable="true" placeholder="招聘说明"
            />
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="工作内容" prop="RecruitDetail.workContent">
            <el-input class="input-item" v-model="formData.RecruitDetail.workContent"
              type="textarea"
              :autosize="{minRows: 2, maxRows: 4}"
              :clearable="true" placeholder="工作内容"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="工作经验" prop="RecruitDetail.workExperience">
            <el-input class="input-item" v-model="formData.RecruitDetail.workExperience"
              type="textarea"
              :autosize="{minRows: 2, maxRows: 4}"
              :clearable="true" placeholder="工作经验"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="开拓能力" prop="RecruitDetail.marketability">
            <el-input class="input-item" v-model="formData.RecruitDetail.marketability"
              type="textarea"
              :autosize="{minRows: 2, maxRows: 4}"
              :clearable="true" placeholder="开拓能力"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="电脑操作" prop="RecruitDetail.computerSkills">
            <el-input class="input-item" v-model="formData.RecruitDetail.computerSkills"
              type="textarea"
              :autosize="{minRows: 2, maxRows: 4}"
              :clearable="true" placeholder="电脑操作"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="外语能力" prop="RecruitDetail.foreignLanguage">
            <el-input class="input-item" v-model="formData.RecruitDetail.foreignLanguage"
              type="textarea"
              :autosize="{minRows: 2, maxRows: 4}"
              :clearable="true" placeholder="外语能力"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="其他标准" prop="RecruitDetail.otherStandards">
            <el-input class="input-item" v-model="formData.RecruitDetail.otherStandards"
              type="textarea"
              :autosize="{minRows: 2, maxRows: 4}"
              :clearable="true" placeholder="其他标准"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-col :span="24">
        <el-row class="no-scroll flex-box" type="flex" justify="end">
          <el-button type="primary" size="mini" :plain="true"
            @click="onCancel(false)">
            取消
          </el-button>
          <el-button type="primary" size="mini"
            @click="onSaveClick">
            保存
          </el-button>
        </el-row>
      </el-col>
    </el-form>
  </div>
</template>

<script>
/* eslint-disable-next-line */
import { findTreeNode, findTreeNodePath, findItemFromList } from '@/utils';

/* eslint-disable-next-line */
import { DropdownWidget} from '@/utils/widget.js';
/* eslint-disable-next-line */
import { uploadMixin, statsDateRangeMixin } from '@/core/mixins';
/* eslint-disable-next-line */
import { DictionaryController } from '@/api';

export default {
  name: 'formEditFlowRecruitDetail',
  props: {
    rowData: {
      type: Object
    }
    
  },
  mixins: [uploadMixin, statsDateRangeMixin],
  data () {
    return {
      formData: {
        RecruitDetail: {
          id: undefined,
          recruitId: undefined,
          post: undefined,
          recruitNumber: undefined, // 招聘人数
          arrivalDate: undefined,
          wages: undefined,
          remark: undefined,
          workContent: undefined, // 工作内容
          workExperience: undefined,
          workExpertise: undefined,
          marketability: undefined,
          writingAbility: undefined,
          computerSkills: undefined,
          foreignLanguage: undefined,
          otherStandards: undefined,
          createUserId: undefined,
          createTime: undefined,
          updateUserId: undefined,
          updateTime: undefined,
          deletedFlag: undefined,
          isDatasourceInit: false
        }
      },
      // // 本地获取数据
      // locality: [],
      // 招聘岗位
      postTypeList: [
        {id: '1', name: '主管'},
        {id: '2', name: '员工'}
      ],
      rules: {
        'RecruitDetail.recruitNumber': [
          {required: true, message: '请输入招聘人数', trigger: 'blur'}
        ],
        'RecruitDetail.post': [
          {required: true, message: '请输入招聘岗位', trigger: 'blur'}
        ],
        'RecruitDetail.workContent': [
          {required: true, message: '请输入工作内容', trigger: 'blur'}
        ],
        'RecruitDetail.workExperience': [
          {required: true, message: '请输入工作经验', trigger: 'blur'}
        ],
        'RecruitDetail.remark': [
          {required: true, message: '请输入招聘说明', trigger: 'blur'}
        ],
        'RecruitDetail.wages': [
          {required: true, message: '请输入招聘薪资', trigger: 'blur'}
        ],
        'RecruitDetail.arrivalDate': [
          {required: true, message: '请输入希望到岗日期', trigger: 'blur'}
        ]
      },
      formEditFlowRecruitDetail: {
        formFilter: {
        },
        formFilterCopy: {
        },
        post: {
          impl: new DropdownWidget(this.loadPostDropdownList)
        },
        isInit: false
      }
    }
  },
  created () {
    this.onEdit()
  },
  methods: {
    onCancel (isSuccess, data) {
      if (this.observer != null) {
        this.observer.cancel(isSuccess, data);
      }
    },
    // 回显
    onEdit () {
      let locality = JSON.parse(sessionStorage.getItem('recruitDetail'))
      // console.log('本地是否有数据', locality)
      if (locality !== null) {
        this.formData.RecruitDetail = locality
      } else {
        this.formData.RecruitDetail = {
          id: undefined,
          recruitId: undefined,
          post: undefined,
          recruitNumber: undefined, // 招聘人数
          arrivalDate: undefined,
          wages: undefined,
          remark: undefined,
          workContent: undefined, // 工作内容
          workExperience: undefined,
          workExpertise: undefined,
          marketability: undefined,
          writingAbility: undefined,
          computerSkills: undefined,
          foreignLanguage: undefined,
          otherStandards: undefined,
          createUserId: undefined,
          createTime: undefined,
          updateUserId: undefined,
          updateTime: undefined,
          deletedFlag: undefined,
          isDatasourceInit: false
        }
      }
    },
    // 招聘-保存
    onSaveClick () {
      let locality = JSON.parse(sessionStorage.getItem('recruitDetail'))
      if (locality == null) {
        this.$refs.formEditFlowRecruitDetail.validate(valid => {
          if (!valid) return;
          let formData = {
            postDictMap: findItemFromList(this.formEditFlowRecruitDetail.post.impl.dropdownList, this.formData.RecruitDetail.post, 'id'),
            ...this.formData.RecruitDetail
          }
          this.onCancel(true, formData);
        });
      } else {
        this.$refs.formEditFlowRecruitDetail.validate(valid => {
          if (!valid) return;
          let formData = {
            postDictMap: findItemFromList(this.formEditFlowRecruitDetail.post.impl.dropdownList, this.formData.RecruitDetail.post, 'id'),
            ...this.formData.RecruitDetail
          }
          this.onCancel(true, formData);
        });
        sessionStorage.removeItem('recruitDetail')
      }
      // console.log('保存后本地状态', locality)
    },
    // 招聘岗位
    onRoomNameValueChange (value) {
      this.formData.RecruitDetail.postC = this.postTypeList.find((item) => item.id === value).name;
    },
    /**
     * 招聘岗位下拉数据获取函数
     */
    loadPostDropdownList () {
      return new Promise((resolve, reject) => {
        let params = {};
        DictionaryController.dictPositionDict(this, params).then(res => {
          resolve(res.getList());
        }).catch(e => {
          reject(e);
        });
      });
    },
    // /**
    //  * 招聘岗位选中值改变
    //  */
    // onPostValueChange (value) {
    // },
    /**
     * 更新编辑付款详情
     */
    refreshFormEditFlowRecruitDetail (reloadData = false) {
      if (!this.formEditFlowRecruitDetail.isInit) {
        // 初始化下拉数据
        if (this.rowData != null) {
          this.formData.RecruitDetail = {
            ...this.rowData
          }
          this.formEditFlowRecruitDetail.post.impl.onVisibleChange(true).catch(e => {});
        }
      }
      this.formEditFlowRecruitDetail.isInit = true;
    },
    initFormData () {
    },
    formInit () {
      this.refreshFormEditFlowRecruitDetail();
    }
  },
  computed: {
  },
  mounted () {
    // 初始化页面数据
    this.formInit();
  },
  watch: {
  }
}
</script>
